#pragma once

#include <iostream>
#include <pthread.h>
#include <string>
#include <ctime>

typedef void(* callback_t)() ;//传进去的只能是无参的

static int num=0;//线程的数量

class Thread
{
public:
    static void *Routiue(void *args)
    {
        Thread*t=static_cast<Thread*>(args);
        t->cb_();  //调用了外部传来的任务；
    }

public:
    Thread(callback_t cb)
    :cb_(cb),isrunning_(false),start_timestamp_(0)
    {}

    void Run()
    {
        name_="thread-"+std::to_string(++num);
        isrunning_=true; //记录运行情况
        start_timestamp_=time(nullptr);  //记录时间
        pthread_create(&tid_,nullptr,Routiue,this);
    }

    void join()
    {
        pthread_join(tid_,nullptr);
    }

    bool IsRunning()
    {
        return isrunning_;
    }

    uint64_t Start_timestamp()
    {
        return start_timestamp_;
    }

    std::string GetName()
    {
        return name_;
    }

    ~Thread()
    {}
private:
    std::string name_;
    pthread_t tid_;
    uint64_t start_timestamp_;
    bool isrunning_;

    callback_t cb_;
};